﻿@model TrialManagmentTool.Models.TrialBasicSummaryViewModel
@{
    ViewBag.Title = "总结报告";
    Layout = "~/Views/Shared/Layout.Mobile.cshtml";
}
<script src="@TrialManagementTool.Helper.UrlHelper.alterContent("Scripts/mobilejs/sm-extend.min.js")"></script>

<style>
    .ctr {
        border-bottom: 1px solid;
    }

    td {
        padding: 6px;
        font-size: 14px;
    }

    input[type=text] {
        color: #000000;
    }

    textarea {
        color: #000000;
    }

    .button-success.button-fill {
        height: 45px;
    }

    .content {
        width: 92%;
    }
</style>
<div class="page-group">
    <div class="page page-current" id="lastreport">
        <div class="content">
            <table style="margin-top:20px;font-size:16px;width:100%">
                <tr id="maindata1" class="ctr">
                    <td style="width:65%">
                        @Model.dataList[0].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span>
                    </td>
                    <td>
                        <input type="text" id='datetime-picker' value="@Model.dataList[0].value" style="background-color:transparent;border:none;color:#ffffff" />
                    </td>
                </tr>

                <tr id="maindata2" class="ctr">
                    <td>
                        @Model.dataList[1].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span>
                    </td>
                    <td>
                        <label class="label-switch">
                            <input type="checkbox" id="isAcceptable" onchange="UpdateCheckboxDesc(this)">
                            <div class="checkbox"><span id="fengbichkdesc" style="margin-left:60px"> </div>
                        </label>
                    </td>
                </tr>

                <tr id="maindata3" class="ctr">
                    <td colspan="2">
                        <div>@Model.dataList[2].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                        <div>
                            <input type="radio" name="effect" value="1">@Model.reportDescList[0].Description
                            <input type="radio" name="effect" value="2" id="c1">@Model.reportDescList[1].Description
                        </div>
                        <div>
                            <input type="radio" name="effect" value="3">@Model.reportDescList[2].Description
                            <input type="radio" name="effect" value="4" id="c2">@Model.reportDescList[3].Description
                        </div>
                    </td>

                </tr>

                <tr id="maindata4" class="ctr">
                    <td colspan="2">
                        <div>@Model.dataList[3].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                        <div><textarea style="width:97%;margin-top:5px" id="effectDescription" ></textarea></div>
                    </td>
                </tr>

                <tr id="maindata5" class="ctr">
                    <td colspan="2">
                        <div>@Model.dataList[4].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                        <div><textarea style="width:97%;margin-top:5px" id="cropDescription"></textarea></div>
                    </td>
                </tr>

                <tr id="maindata6" class="ctr">
                    <td colspan="2">
                        <div>@Model.dataList[5].ChineseDesc</div>
                        <div><textarea style="width:97%;margin-top:5px" id="yieldsEffert"></textarea></div>
                    </td>
                </tr>
                <tr id="maindata7" class="ctr">
                    <td colspan="2">
                        <div>@Model.dataList[6].ChineseDesc</div>
                        <div><textarea id="comments" style="width:97%;margin-top:5px"></textarea></div>
                    </td>
                </tr>
            </table>
            <div class="content-block">
                <div class="row">
                    @if (Model.TrialStatus == 0 || Model.TrialStatus == 1)
                    {
                        <div class="col-50"><a href="#" class="button button-fill button-success" onclick="location.href='@TrialManagementTool.Helper.UrlHelper.alterContent("TrialMobile/ReportManagement?id="+Model.ID)'">返回列表</a></div>
                        <div class="col-50"><a href="#" class="button button-fill button-success" id="submitReport">保存</a></div>
                    }
                    else
                    {
                        <div><a href="#" class="button button-fill button-success" onclick="location.href='@TrialManagementTool.Helper.UrlHelper.alterContent("TrialMobile/ReportManagement?id="+Model.ID)'">返回列表</a></div>
                    }
                </div>
            </div>
        </div>
        <div style="position:absolute;right:0;top:100px;z-index:2001">
            <a class="filterArea" onclick="loadPage()"> <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/fangan.png")" class="fangan" />  </a>
        </div>
    </div>
    <div class="page" id="purpose">
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left" href="#lastreport">
                <span class="icon icon-left"></span>
                返回
            </a>
            <h1 class='title'>示例方案</h1>
        </header>
        <div class="content" style="width:90%">

            @{var data = new ViewDataDictionary();

            data.Add("TrialGuideID", @Model.TrialGuideID);
            Html.RenderPartial("Purpose", null, data); }
        </div>
    </div>
</div>
@for (int i = 0; i < Model.dataList.Count(); i++)
{
    if (Model.dataList[i].display == false)
    {
        <script>
            $("#maindata" + (@i+1)).css("display", 'none');
        </script>
    }
}
<script>
    Zepto(function ($) {
        if (!('@Model.TrialStatus' == 0 || '@Model.TrialStatus' == 1)) {
            $("input[type=text]").attr("disabled", "disbaled");
            $("input[type=radio]").attr("disabled", "disbaled");
            $("input[type=number]").attr("disabled", "disbaled");
            $("input[type=checkbox]").attr("disabled", "disbaled");
            $("textarea").attr("disabled", "disbaled");
            $("select").attr("disabled", "disbaled");
        }
        $("#c1").css('margin-left', $($("#maindata1 td")[0]).attr('scrollWidth') - 70);
        $("#c2").css('margin-left', $($("#maindata1 td")[0]).attr('scrollWidth') - 57);

        if ('@Model.dataList[2].value' != 0) {
            $("input[name='effect'][value='" +@Model.dataList[2].value +"']").attr("checked", "true");
        }
        if ('@Model.dataList[1].value' == "True") {
            $("#isAcceptable").attr("checked", "true");
            $("#fengbichkdesc").html("是");
        } else {
            $("#fengbichkdesc").html("否");
        }
        $("#effectDescription").val(FormatTextAreaValue('@Model.dataList[3].value'));
        $("#cropDescription").val(FormatTextAreaValue('@Model.dataList[4].value'));
        $("#yieldsEffert").val(FormatTextAreaValue('@Model.dataList[5].value'));
        $("#comments").val(FormatTextAreaValue('@Model.dataList[6].value'));
    })
    function loadPage() {
        $.router.load("#purpose");
        init();
    }

    if ('@Model.dataList[0].value.Length' > 5) {
        var date = '@Model.dataList[0].value'.split('-');
        $("#datetime-picker").datetimePicker({
            value: [date[0], date[1], date[2], date[3], date[4]]
        });
    } else {
        $("#datetime-picker").datetimePicker({
        });
    }
    $("#submitReport").click(function () {
        if ($("#datetime-picker").val() == "" && $("#maindata1").css('display') != "none") {
            $.toast("最后一次调查时间不能为空");
        } else if ($("input[name='effect']:checked").val() == undefined && $("#maindata3").css('display') != "none") {
            $.toast("最后一次调查目测药效不能为空");
        } else if ($("#cropDescription").val() == "" && $("#maindata4").css('display') != "none") {
            $.toast("具体药效描述(动态过程)不能为空");
        } else if ($("#effectDescription").val() == "" && $("#maindata5").css('display') != "none") {
            $.toast("其它说明不能为空");
        } else {
            var postData = { FinalSummarySubmitModel: {} }
            postData.TrialID = '@Model.ID';
            postData.LastObserveDate = $("#datetime-picker").val();
            postData.EffectResult = $("input[name='effect']:checked").val();
            postData.EffectDescription = encodeTextAreaString($("#effectDescription").val());
            postData.IsAcceptable = $("#isAcceptable").is(':checked');
            postData.Comments = encodeTextAreaString($("#comments").val());
            postData.YieldsEffert = encodeTextAreaString($("#yieldsEffert").val());
            postData.CropDescription = encodeTextAreaString($("#cropDescription").val());
            $.ajax({
                url: fixUrl("api/Trial/SubmitFinalReport"),
                type: "post",
                data: postData,
                success: function (data) {
                    if (data.status == "Success") {
                        $.toast("提交成功.");
                        setTimeout(function () {
                            location.href = fixUrl("TrialMobile/TrialManagement");
                        }, 2000)
                    } else {
                        $.alert('保存失败,请重试');
                    }
                },
                error: function (data) {
                    if (data.status == "401") {
                        $.alert('登录超时');
                    } else {
                        $.alert('保存失败,请重试');
                    }
                }
            })
        }

    })

    function UpdateCheckboxDesc(target) {
        if ($("#" + target.id).is(':checked') == true) {
            $("#fengbichkdesc").html("是");
        } else {
            $("#fengbichkdesc").html("否");
        }
    }
</script>
